import { Result } from './../../../../model/Result.d';
import { Component, Injector } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { BasePage } from '../../../basePage';
import { StorageService } from './../../../../providers/StorageService';
import { PIC_URL } from "./../../../../providers/Config";
import { nailerService } from './../../../../providers/nailerService';
import { UserService } from '../../../../providers/UserService';

/**
 * Generated class for the BillDetailPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-bill-detail',
  templateUrl: 'bill-detail.html',
})
export class BillDetailPage extends BasePage {
  userinfo: {}   //读取的用户信息
  picrooturl; //图片服务地址
  data: any;     //美甲师账单号
  data2: any;     //美甲店账单号
  catogary='';    //美甲店收益支出种类，售出服务或购买款式
  data3:any;      //消费者账单号
  billDetail = [];
  billDetail2=[]
  billDetail3=[];

  /*请求参数*/
  param = {
    order_sn: ""
  }

  isOk:boolean;   //美甲师
  isOk2:boolean;  //美甲店
  isOk3:boolean;  //消费者
  constructor(injector: Injector, public nailerService: nailerService, public stc: StorageService, public userService: UserService) {
    super(injector);
    this.picrooturl = PIC_URL;
    this.userinfo = this.stc.read('userinfo');
    this.data = this.navParams.get('order_sn'); //美甲师账单号
    this.data2 = this.navParams.get('order_sn2'); //美甲店账单号
    this.catogary = this.navParams.get('cato');
    this.data3 = this.navParams.get('order_sn3'); //消费者账单号
    // if(this.data==undefined){
    //   this.isOk=false;
    //   this.isOk2=true;
    // }
    // if(this.data2==undefined){
    //    this.isOk=true;
    //    this.isOk2=false;
    // }
    console.log(this.data+" "+this.data2+" "+this.data3);
  }

  ionViewDidLoad() {
    if(this.data != undefined){
      console.log("这是美甲师的");
      this.isOk=true;
      this.isOk2=false;
      this.isOk3=false;
      this.getBillDetail();
    }
    if(this.data2 != undefined){
      console.log("这是美甲店")
      this.isOk=false;
      this.isOk2=true;
      this.isOk3=false;
      this.getBillDetail2()
    }
    if(this.data3 != undefined){
      console.log("这是消费者")
      this.isOk=false;
      this.isOk2=false;
      this.isOk3=true;
      this.getBillDetail3();
    }
    console.log('ionViewDidLoad BillDetailPage');
  }

  dismissCLI() {
    this.viewCtrl.dismiss(1);
  }


  /*获取美甲师账单详情*/
  async getBillDetail() {
    this.billDetail = [];
    this.param.order_sn = this.data;
    let result = await this.nailerService.artistIncomeDetailsAPI(this.param);
    console.log(result)
    if (result.code == 1) {
      this.billDetail = result.data;
    } else {
      let toast = this.toastCtrl.create({
        message: result.msg,
        duration: 1500,
        position: 'bottom',
      })
      toast.present();
    }
  }
  //获取美甲店账单详情
  async getBillDetail2() {
    this.billDetail2 = [];
    this.param.order_sn = this.data2;
    console.log(this.param)
    let result = await this.nailerService.showOrderAPI(this.param);
    console.log(result)
    if (result.code == 1) {
      this.billDetail2 = result.data;
    } else {
      let toast = this.toastCtrl.create({
        message: result.msg,
        duration: 1500,
        position: 'bottom',
      })
      toast.present();
    }
  }
  //获取消费者账单详情
  async getBillDetail3(){
    this.billDetail3 = [];
    let param={order_sn:this.data3};
    console.log(param);
    let result=await this.userService.userOrderInfoAPI(param);
    console.log(result);
    if(result.code ==1){
      this.billDetail3=result.data;
    }else{
      let toast = this.toastCtrl.create({
        message: result.msg,
        duration: 1500,
       position: 'bottom',
      })
      toast.present();
    }
  }
}
